package com.example.demo.entity;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class User {
    private Long userId;
    // 个人信息包括姓名、性别、年龄、职业、部门（一个人可能有多个部门，也可能没有部门）。
    @NotBlank(message = "姓名不为空")
    private String name;
    @NotBlank(message = "性别不为空")
    private String sex;
    private Integer age;
    private String occupation;
    private List<Long> departIds;

    public User(String name, String sex, int age, String occupation, String departIds) {
        this.name = name;
        this.sex = sex;
        this.age = age;
        this.occupation = occupation;
        this.departIds = Arrays.stream(departIds.split(",")).
                map(s -> Long.parseLong(s)).
                collect(Collectors.toList());
    }


}
